package com.example.mapp;

import com.example.entity.DailyInspection;
import com.example.ext.entity.ExtDailyInspection;
import com.example.mapp.buildSql.DailyInspectionMappSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by youkun on 2017/9/22.
 */
@Mapper
public interface DailyInspectionMapp {

    @Select(" select a.*, b.user_name as checkUserName, c.elevator_num as elevatorNum " +
            " from daily_inspection a " +
            " left join sys_user b on a.check_user_id = b.id " +
            " left join elevator c on a.elevator_id=c.id " +
            " where a.id=#{id}")
    ExtDailyInspection queryById(String id) throws Exception;

    @SelectProvider(type = DailyInspectionMappSql.class,method = "queryList")
    List<ExtDailyInspection> queryListByElevatorId(ExtDailyInspection extDailyInspection) throws Exception;

    @Delete("delete from daily_inspection where id=#{id}")
    int  deleteById(String id) throws Exception;

    @Update(" update daily_inspection set elevator_id=#{elevatorId} where id=#{id} ")
    public int update(DailyInspection dailyInspection) throws Exception;

    @Insert(" insert into daily_inspection (elevator_id,remarks,other,inspection_summary,check_user_id,is_unusual,check_start_dt,check_end_dt," +
            "sign_pic_url,instructions_clear,car_interior_lighting,emergency_lighting, emergency_alarm_device,door_clip_holder,switch_door_flexible," +
            "running_without_exception,operation_level_normal,layer_button_normal,call_button_normal,floor_monitor_normal,staircase_light_normal," +
            "door_no_deformation,gate_no_gap,access_and_lighting,distribution_box_locked,normal_call,controller_no_dust,contactor_no_noise,machine_no_exception," +
            "emergency_procedures_clear) " +
            " value " +
            " (#{elevatorId},#{remarks},#{other},#{inspectionSummary},#{checkUserId},#{isUnusual},#{checkStartDt},#{checkEndDt},#{signPicUrl},#{instructionsClear}," +
            "#{carInteriorLighting},#{emergencyLighting}, #{emergencyAlarmDevice},#{doorClipHolder},#{switchDoorFlexible},#{runningWithoutException},#{operationLevelNormal}," +
            "#{layerButtonNormal},#{callButtonNormal},#{floorMonitorNormal},#{staircaseLightNormal},#{doorNoDeformation},#{gateNoGap},#{accessAndLighting},#{distributionBoxLocked}," +
            "#{normalCall},#{controllerNoDust},#{contactorNoNoise},#{machineNoException},#{emergencyProceduresClear}) ")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    public int add(DailyInspection dailyInspection) throws Exception;
}
